package com.demo.common.aop;

import java.util.Map;

import com.demo.common.annotation.CustomAnnotation;
import com.demo.entities.User;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint;
import org.springframework.stereotype.Component;

/**
 * spring AOP方法后处理
 *
 * @author jie_r
 */
@Component
@Aspect
public class CustomAspect {

    public CustomAspect() {
        System.out.println("**************被扫描***************");
    }

    /**
     * 定义Pointcut，Pointcut的名称 就是simplePointcut，此方法不能有返回值，该方法只是一个标示
     */
//    @Pointcut("execution(* com.demo.service.impl.UserServiceImpl.getUserDataById(..))")
    @Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
    public void init() {
    }
//
//    @Before("execution(* com.demo.service.impl.UserServiceImpl.getUserDataById(..))")
//    public void doBefore() {
//        System.out.println("**************加载前***************");
//    }

    @Around(value = "init()&&@annotation(customAnnotation)", argNames = "joinPoint,customAnnotation")
    public Object permission1(ProceedingJoinPoint joinPoint, CustomAnnotation customAnnotation) throws Throwable {
        customAnnotation.permission();
        System.out.println("--11111111111111111111111----");
        return joinPoint.proceed();
    }
}
